
$(function(){
// ===========================================顶部显示隐藏部分
	function Show(tab) {
		this.tab = $(tab);
		this.con = $(tab).children('.dropdown');
		// console.log(this.con)
		this.init();
	}
	Show.prototype.init = function(){
		this.initHide();
		this.showEnter();
	}
	Show.prototype.initHide = function(){
		this.con.hide();
	}
	Show.prototype.showEnter = function() {
		var _this = this;
		this.tab.hover(function() {
			_this.con.show();
		}, function() {
			_this.con.hide();
		});
	}
	var phoneDrop = new Show('#phone');
	var service = new Show('#service');
// 导航切换
	function watchTit(nav,con) {
		// console.log($(nav))
		$(con).mouseenter(function() {
			$(this).show();
		});
		$(con).mouseleave(function() {
			$(this).hide();
		});
		$(nav).mouseenter(function() {
			$(con).show();
		});
		$(nav).mouseleave(function() {
			$(con).hide();
		});

	}
	watchTit('.nav .nav-tit','.nav .menu');
	watchTit('.nav .select','.nav-box .dropbox');

	var selectPage=(function(){
		function headerTab(tab,content){
			$(content).mouseenter(function() {
				$(this).show();
			});
			$(content).mouseleave(function() {
				$(this).hide();
			});
			$(tab).mouseenter(function() {
				$(this).addClass('active')
				$(this).next(content).show()
			});
			$(tab).mouseleave(function() {
				$(this).next(content).hide()
				$(this).removeClass('active')
			});
			
		}
		function fixed() {
			$(document).on('scroll',function(){
				var _top = $(this).scrollTop();
				// console.log(_top);
				if(_top>=700) {
					$('.sort-list').addClass('fixedsort')
				}else {
				$('.sort-list').removeClass('fixedsort')
				}
			})
		}
		//内容鼠标hover
		function hover() {
			$('.goods-list .pTag02').hide();
			$('.goods-list .hover-info').hide();

			$('.goods-list').hover(function() {
				$(this).find('.pTag01').hide();
				$(this).find('.pTag02').show();
				$(this).find('.hover-info').show();
			}, function() {
				$(this).find('.pTag02').hide();
				$(this).find('.hover-info').hide();
				$(this).find('.pTag01').show();
			});
		}

		function banner(slider,className,t){
			//初始化变量
			var banner = $(slider), //banner
				imgUl = banner.children().eq(0),//图片ul
				imgLi = imgUl.children(),
				btnUl = banner.children().eq(1),
				btnLi = btnUl.children("i"),
				W = banner.width(), //单个图片的宽度
				len = imgLi.size(),//图片的个数
				cur = 0,
				btnIndex;
				//克隆第一幅图片
				imgUl.append(imgLi.eq(0).clone());
				//设置图片ul的宽度
				imgUl.width((len+1)*W);
			//处理分页按钮
			function pageBtn(){
				if (cur==len){
					btnIndex = 0;
				}else{
					btnIndex = cur;
				}
				btnLi.eq(btnIndex).addClass(className).siblings().removeClass(className);
			}
			//运动函数
			function move(){
				if (cur == len+1){
					imgUl.css({left: 0});
					cur = 1;
				}
				pageBtn();
				imgUl.stop().animate({left: -cur*W},1000);     
			}
			//网页加载后，动画开始
			var timer = setInterval(function(){
				cur++;
				move();
			},t);
			//当鼠标经过时，停止
			banner.mouseenter(function(){
				clearInterval(timer);
			});
			//当鼠标离开时，继续
			banner.mouseleave(function(){
				timer = setInterval(function(){
					cur++;
					move();
				},t);
			});
			//单击分页按钮
			btnLi.click(function(){
				cur = $(this).index();
				move();
			});
		};
		// 手表咨询，网站承诺tab切换
		function moudleTab(wrap,con,classname) {
			var $tab = $(wrap).children().eq(0).children();

			var $con = $(wrap).children(con)
			// console.log($con)
			$tab.hover(function() {
				$(this).siblings().removeClass(classname).end().addClass(classname);
				$con.hide().eq($(this).index()).show();
			});
		}
		//热门手表点击更多
		function more() {
			$('.line-top .more').click(function() {
				if($(this).parent('.line-top').next('.lines-freemode-wrap').css('height')=="26px") {
					$(this).parent('.line-top').next('.lines-freemode-wrap').css('height','auto')
				}else {
					$(this).parent('.line-top').next('.lines-freemode-wrap').css('height',26)
				}
			});
		}
		//单行滚动
		function WordScrollLeft(){
			var speed=50;
			var timer=null;
			var booking_now=document.getElementById("booking_now");
			var infoHtml = $("#booking_info").html();
			$("#booking_info_box").html(infoHtml);
			function Marquee() {
				var widths=$("#booking_now").width();
				if(booking_info.offsetWidth<$("#booking_now").width()){
					return false;
				}else{
					booking_info.style.visibility="visible";
					if(booking_info.offsetWidth -booking_now.scrollLeft<=0){
						booking_now.scrollLeft -=booking_info_box.offsetWidth;
					}else{
						booking_now.scrollLeft++;
					}
				}
			}
			timer=setInterval(Marquee,speed);
		}
		return {
		WordScrollLeft:WordScrollLeft,
		headerTab:headerTab,
		fixed:fixed,
		hover:hover,
		banner:banner,
		moudleTab:moudleTab,
		more:more,
		scroll:scroll,
		};
		
		
	}());
	
selectPage.WordScrollLeft()
	selectPage.headerTab('.nav .box','.nav .submenu');
	selectPage.fixed()
	selectPage.hover();
	selectPage.banner('.bx-wrapper','active','1600');
	// selectPage.moudleTab('.moudle-top ul li','.moudle-con .tab-con','current');
	selectPage.moudleTab('#tab1','.code-con','code-in');
	selectPage.moudleTab('#tab2', '.code-con','code-in');
	selectPage.banner('.moudle-con .bx-viewport','active','1600')
	selectPage.more()

	

})